﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Kalficom
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
            conf.Icon(this, true);
        }

        private void txtPassword_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Libraies.db db = new Libraies.db();
                string _cur_user = db.ExecuteScalar(string.Format("SELECT user_id FROM k_user WHERE user_login={0} AND user_pwd={1}"
                    , db.SqlString(txtLogin.Text)
                    , db.SqlString(txtPassword.Text)));

                conf.CurUser = _cur_user == "" ? 0 : int.Parse(_cur_user);
                if (conf.CurUser == 0)
                    MessageBox.Show((new Libraies.msg()).logFail, (new Libraies.msg()).captionMsg, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                else
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            txtPassword_KeyUp(null, new KeyEventArgs(Keys.Enter));
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
